// 利用递归的方式进行
// 深度优先遍历
function generateParent(n) {
    let res = [];
    const dfs = (current, left, right) => {
        if (current.length == 2 * n) {
            res.push(current);
            return;
        }
        if (left < n) {
            dfs(current + "(", left + 1, right)
        }
        if (right < left) {
            dfs(current + ")", left, right + 1)
        }

    }
    dfs("", 0, 0);
    return res;
}

console.log(generateParent(3))